<template>
  <div>
    <r-search ref="search" :searchData="searchData" :searchForm="searchForm" :searchHandle="searchHandle"
      :inline="true" />
    <!-- 模板导出 -->
    <r-search :searchHandle="searchHandleAdd" />
    <r-table :isPagination="true" :isHandle="true" :tableData="tableData" :tableCols="tableCols" :tablePage="pagination"
      :loading="tableLoading" :tableHandles="tableHandles" :isSelection="false" @refresh="page()" />
  </div>
</template>

<script>
  export default {
    data() {
      return {
        // 模板导出数据
        searchHandleAdd: [
          {
            label: "导出数据",
            icon: "el-icon-download",
            type: "success",
            loading: false,
            handle: async e => {
              const res = await this.apis.mealOrderExport(this.searchData);
              console.log("res---", res);
              location.href =
                process.env.VUE_APP_URL + "/profile/download/" + res.msg;
            }
          }
        ],
        searchData: {
          orderNo: "",
          phone: "",
          nickName: "",
          mealName: "",
          ctime: "",
          validTime: ""
        },
        searchForm: [
          { type: "input", placeholder: "订单编号", prop: "orderNo", width: 200 },
          { type: "input", placeholder: "手机号", prop: "phone", width: 200 },
          {
            type: "input",
            placeholder: "用户昵称",
            prop: "nickName",
            width: 200
          },
          {
            type: "input",
            placeholder: "套餐名称",
            prop: "mealName",
            width: 200
          },
          {
            type: "date",
            placeholder: "开始日期",
            prop: "ctime",
            width: 180,
            change: val => {
              this.searchData.ctime = val;
            }
          },
          {
            type: "date",
            placeholder: "结束日期",
            prop: "validTime",
            width: 180,
            change: val => {
              this.searchData.validTime = val;
            }
          }
        ],
        searchHandle: [
          { type: "primary", label: "搜索", handle: e => this.getData() }
          // {type:'primary',label:'重置', handle: e => this.elFormSubmit(),}
        ],
        tableLoading: false,
        tableData: [],
        tableCols: [
          { label: "订单编号", prop: "orderNo" },
          { label: "套餐名称", prop: "mealName" },
          { label: "用户昵称", prop: "nickName" },
          { label: "手机号", prop: "phone" },
          {
            label: "天数",
            prop: "days",
            formatter: e => (e.days ? e.days + "天" : "--")
          },
          {
            label: "次数",
            prop: "nums",
            formatter: e =>
              e.nums === -1 ? "不限次" : e.nums ? e.nums + "次" : "--"
          },
          {
            label: "价格",
            prop: "price",
            formatter: e => (e.price ? e.price + "元" : "--")
          },
          {
            label: "使用的余额金额",
            prop: "balanceMoney",
            formatter: e => (e.balanceMoney ? e.balanceMoney + "元" : "--")
          },
          {
            label: "现付金额",
            prop: "cashMoney",
            formatter: e => (e.cashMoney ? e.cashMoney + "元" : "--")
          },
          {
            label: "实付金额",
            prop: "countMoney",
            formatter: e => (e.countMoney ? e.countMoney + "元" : "--")
          },
          { label: "支付时间", prop: "payTime" },
          { label: "套餐到期时间", prop: "validTime" }
        ],
        tableHandles: [
          // {
          //   label: "数据导出",
          //   type: "primary",
          //   handle: e => this.elFormVisible()
          // },
        ],
        pagination: { limit: 10, offset: 1, total: 1 }
      };
    },
    mounted() {
      this.getData();
    },
    methods: {
      async getData() {
        let parm = {
          ...this.searchData,
          ...{
            pageNum: this.pagination.offset,
            pageSize: this.pagination.limit
          }
        };
        let res = await this.apis.PackageOrderPost(parm);
        this.tableData = res.rows || [];
        this.pagination.total = res.total || 0;
      },
      page() {
        this.getData();
      }
    }
  };
</script>

<style scoped lang="scss"></style>